/*
  Programa Wifis, 2010-2011
  Autor: Nilhcraiv

This file is part of Wifis.

    Wifis is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Wifis is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Wifis.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UPDATESTHREAD_H
#define UPDATESTHREAD_H

#include <QString>
#include <QFile>
#include <QNetworkAccessManager>
#include <QWidget>
#include <QObject>
#include <QMainWindow>
#include <QProgressDialog>
#include <QtCore/QThread>
#include <QUrl>
#include <QNetworkReply>
#include <QProgressDialog>
#include <QTextCodec>
#include <QDialogButtonBox>
#include <QAbstractButton>

class updatesThread : public QWidget //Heredo de qWidget para pasar this, el dialodo QProgressDialog, aunque no haría falta.
{
    Q_OBJECT

public:
    updatesThread(QWidget *parent = 0, double *version=0,bool *inicio=0);
    ~updatesThread();

    void ejecutar();

protected:
    void run();

private:
    QUrl url;
    QNetworkReply *reply;
    QNetworkAccessManager *qnam;
    QFile *file;
    double versionServidor, versionInstalada;
    bool hayError;
    QString fileDownload;
    void downloadNewVersion();
    bool *isStart;
    QByteArray textoUpdates;

private slots:
    void finished();
    void readyRead();
    void error(QNetworkReply::NetworkError code);
    void errorCheckUpdates(QNetworkReply::NetworkError code);
    void updateDataReadProgress(qint64,qint64);
    void finishDownload();
    void readyReadByteArray();

public slots:
    void checkLinkdownloadNewVersion();

signals:
    void closeProgressDialog();
    void setTextDialog(QString);
    void setTextCancelDialog(QString);
    void showDialog(bool);
    void setTextCaptionDialog(QString);
    void addButtonDialog(QString texto,QDialogButtonBox::ButtonRole role);
    void removeButtonDialogUpdate();
    void bytesTotal(int);
    void bytesRead(int);

    void blockSignalsQTimer(bool block);
};

#endif // UPDATESTHREAD_H
